package com.stone.business.zbtz.action;
/**
 * ----安全管理  ACTION---
 */
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;

import com.stone.business.zbtz.pojo.TAqgl;
import com.stone.business.zbtz.pojo.TZbtz;
import com.stone.business.zbtz.service.ZbtzService;
import com.stone.para.IConstant;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.pojo.TOrgan;
import com.stone.sys.pojo.TUser;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.DateFormatTool;
import com.stone.utils.JsonUtils;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseAction;
import frm.ssh.exception.AppException;
import frm.ssh.util.SpringUtil;

public class AqglAction extends BaseAction{
	private ZbtzService zbtzService;
	private TAqgl entity;
	private String id;
	private String hiddenids;
	private List list;
	private String datafrom;
	private String showtype;
	private String directFlag;
	private String cllb;
	private String clmcPram;
	// 设备类型
	private List<TDictionary> sblxList;
	/**
	 * 进入安全管理记录详细页面
	 * 
	 * @return
	 * @throws AppException
	 */
	public String initAqglDetail() throws AppException {
		
		// 修改进入
		 if (!"0".equals(id.toString())) {
			
			this.entity = (TAqgl) zbtzService.findById(Long.parseLong(id),TAqgl.class.getName());
			

		// 新建进入
		} else {
			
			this.entity = new TAqgl();
			entity.setCjr(((TUser) super.getSession().getAttribute(IConstant.SESSION_TUSER)).getName());
			entity.setCjrid(((TUser) super.getSession().getAttribute(IConstant.SESSION_TUSER)).getId());
		
			 String sysdate = zbtzService.getSysdate("yyyy-MM-dd");
			this.entity.setDantype(super.getSearchBean().getCon6());
			
		}
		
		//初始化材料相关列表 added by cheng 2012-5-21
		initClList();
		if(super.getSearchBean().getCon6().equals("1")){
			return "FXD_SUCCESS";
		}else {
			return "BWL_SUCCESS";
		}
		/*if(directFlag==null||directFlag.equals("")){
			return "XJ_SUCCESS";
		}else{
			return directFlag;
		}*/
		
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws AppException
	 */
	public String saveAqgl() throws AppException {
       //String sysdate = zbtzService.getSysdate("YYYY-MM-DD");
		String sysdate =zbtzService.getSysdate("yyyy-MM-dd HH24:mi");
       if (entity.getId() == 0) {
    	   entity.setCjsj(DateFormatTool.formatToDate(sysdate,true));
    	   zbtzService.save(entity);		
       }else{
    	   zbtzService.update(entity);
       }
		String forword="";
		/*if(super.getSearchBean().getCon6().equals("2")||"2".equals(this.entity.getDantype())){
			forword="XJ_SUCCESS";
			}else{
				forword="XJ_SUCCESS";
			}*/
		//String rtn = zbtzService.doSave(this.entity, this.clkcmxList);
		super.setInfo("保存成功");
		//初始化班组相关列表 added by wangtao 2013-4-3
		initClList();
		if(super.getSearchBean().getCon6().equals("1")){
			return "FXD_SUCCESS";
		}else {
			return "BWL_SUCCESS";
		}
		//return forword;

	}
	
	/**
	 * 删除
	 * 
	 * @return
	 * @throws AppException
	 */
	public String deleteAqgl() throws AppException {
		
		zbtzService.doDelAll(id, TAqgl.class.getName());
		
		return "DELETE_SUCCESS";
	}
	
	

	/**
	 * 保存
	 * 
	 * @return
	 * @throws AppException
	 */
	public String save() throws AppException {
		
		String   selectpage=super.getSearchBean().getCon1();
		
		Date confDate = DateFormatTool.formatToDate(zbtzService.getSysdate("yyyy-MM-dd HH24:mi"), true);
		if (this.entity.getId() == 0) {
			
			//this.entity.setOuid(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE).toString());
		}
		//String rtn = zbtzService.doSave(this.entity, this.clkcmxList);
		//初始化材料相关列表 added by wangtao 2012-5-22
		initClList();
		//super.setInfo(rtn);

		return SUCCESS;

	}
	
	public void setZbtzService(ZbtzService zbtzService) {
		this.zbtzService = zbtzService;
	}

	public TAqgl getEntity() {
		return entity;
	}

	public void setEntity(TAqgl entity) {
		this.entity = entity;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getHiddenids() {
		return hiddenids;
	}

	public void setHiddenids(String hiddenids) {
		this.hiddenids = hiddenids;
	}
	
	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public String getDatafrom() {
		return datafrom;
	}

	public void setDatafrom(String datafrom) {
		this.datafrom = datafrom;
	}

	public String getShowtype() {
		return showtype;
	}

	public void setShowtype(String showtype) {
		this.showtype = showtype;
	}

	public ZbtzService getZbtzService() {
		return zbtzService;
	}

	

	public String getDirectFlag() {
		return directFlag;
	}

	public void setDirectFlag(String directFlag) {
		this.directFlag = directFlag;
	}

	

	private void initClList() throws AppException{
		DictionaryService dicService = (DictionaryService) SpringUtil.getInstance().getBean("dicService");
		//设备类型
		sblxList = dicService.findList("SBLX");
	}

	public String getCllb() {
		return cllb;
	}

	public void setCllb(String cllb) {
		this.cllb = cllb;
	}


	public String getClmcPram() {
		return clmcPram;
	}

	public void setClmcPram(String clmcPram) {
		this.clmcPram = clmcPram;
	}

	public List<TDictionary> getSblxList() {
		return sblxList;
	}

	public void setSblxList(List<TDictionary> sblxList) {
		this.sblxList = sblxList;
	}

	

	
}
